package com.neusoft.ysu.his.controller;


import com.auth0.jwt.interfaces.DecodedJWT;
import com.neusoft.ysu.his.entity.CommonResult;
import com.neusoft.ysu.his.entity.Register;
import com.neusoft.ysu.his.service.IRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;

import static com.neusoft.ysu.his.util.JWTUtil.verify;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 作者：赵子鉴
 * @since 2023-08-29
 */
@RestController
@RequestMapping("/register")
@CrossOrigin
public class RegisterController {
    @Autowired
    IRegisterService registerService;
    @GetMapping("/q/byregnum/{regnum}")
    public CommonResult findByRegnum( @PathVariable int regnum){
        System.out.println("1");
        return registerService.findByRegnum(regnum);
    }
    @GetMapping("/q/byname/{name}")
    public CommonResult findByName( @PathVariable int name){
        System.out.println("1");
        return registerService.findByName(name);
    }
    @GetMapping("q/all")
    public CommonResult findAll(){
        return registerService.findAll();
    }
    @PutMapping("/add")
    public CommonResult insert(@RequestBody Register register)
    {
        register.setId(null);
        register.setDelmark(0);
        return registerService.insert(register);
    }
    @PostMapping("/update")
    public CommonResult update(@RequestBody Register register)
    {
        return registerService.update(register);
    }
    @PostMapping("/delet")
    public CommonResult deleteByRegnum(@RequestBody Register register){
        return registerService.deleteByRegnum(register);
    }
    @PostMapping("/q/login")
    public CommonResult loginCheck(@RequestBody Register register) throws UnsupportedEncodingException {
        return registerService.loginCheck(register);
    }
//    @PostMapping("/checktoken")
//    public CommonResult checkToken(@RequestBody String token) throws UnsupportedEncodingException {
//        DecodedJWT decodedJWT= verify(token);
//        return new CommonResult<>(true);
//    }
}
